Thread: Memory issue with new[] and delete[]

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #14
    Registered User
    Join Date
    Jul 2004
    Posts
    27
    Code:
      char* file_buffer = new char[filesize + 1];
      fread (file_buffer, filesize, 1, handle);
      file_buffer[filesize] = '\0';
      file_buffer = strchr(file_buffer, '\n') + 1;
      file_buffer = strchr(file_buffer, '\n') + 1;
      delete[] file_buffer;
    Segmentation fault yet again...
    I don't get the faults if I don't do two of the strchr's, but I need to get down two lines in this x_X

    edit: Oddly enough, if I make the last strchr + 1 to strchr + 2, I don't get a segmentation fault...

    I'm just going to rewrite the parser, prolly end up a lot smaller too x_X

    Thanks for the help guys =).
    Last edited by Zarkhalar; 08-05-2004 at 07:49 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 14
    Last Post: 06-28-2006, 01:58 AM
  2. Replies: 8
    Last Post: 01-17-2006, 05:39 PM
  3. delete[] without new[]?
    By ChadJohnson in forum C++ Programming
    Replies: 6
    Last Post: 04-04-2005, 11:39 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. allocating memory screws up data being read in from file
    By Shadow12345 in forum C++ Programming
    Replies: 5
    Last Post: 12-06-2002, 03:23 PM